﻿using System;


//以后mono里面调用Main就可以
public abstract class FSMMain<T> where T:Enum
{    
    public FSMAINodeBase<T> ActiveNode{protected set;get;}
    public T Status {protected set; get; }



    public void ChangeStatus(T value)
    {
        LeaveStatus();
        Status = value;
        ActiveStatus(value);
        EnterStatus();
    }



    protected void RunNode()
    {
        if(ActiveNode==null)
            return;

        var result = ActiveNode.RunningNode();
        if(result)
            ChangeStatus(ActiveNode.NextState);
    }


    protected virtual void LeaveStatus()
    {
        if(ActiveNode==null)
            return;
            
        ActiveNode.LeaveNode();
    }

    protected virtual void EnterStatus()
    {
        if(ActiveNode==null)
            return;

        ActiveNode.EnterNode();
    }

    protected abstract void ActiveStatus(T status);
}
